<?php
/**
 * Created by IntelliJ IDEA.
 * User: jirapatjantsakool
 * Date: 5/5/14
 * Time: 9:50 AM
 */


header("Content-type:application/json; charset=UTF-8");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);

require('../util/mailutil.php');
require('../service/configure_service.php');


$wsname = $_REQUEST['wsname'];
$tokeyKey = $_REQUEST['token'];


class mailaction
{

    public function isValidateToken($tokeyKey)
    {
        $configure_service = new configure_service();
        return $configure_service->isValidateTokenKey($tokeyKey);
    }


}

$mailaction = new mailaction();


if ($mailaction->isValidateToken($tokeyKey)) {

    if ($wsname == 'sendmailtome') {

        $name = isset($_REQUEST['name']) ? $_REQUEST['name'] : null;
        $telephone = isset($_REQUEST['telephone']) ? $_REQUEST['telephone'] : null;
        $fromemail = isset($_REQUEST['fromemail']) ? $_REQUEST['fromemail'] : null;
        $subject = isset($_REQUEST['subject']) ? $_REQUEST['subject'] : null;
        $message = isset($_REQUEST['message']) ? $_REQUEST['message'] : null;

        $toemail = 'jewel.jirapat@gmail.com';

        $headers = "MIME-Version: 1.0\r\n" ;
        $headers .= "Content-type: text/html; charset=windows-874\r\n" ; // ส่งข้อความเป็นภาษาไทย ใช้ "windows-874"
        $headers .= "From: ".$fromemail." <".$fromemail.">\r\n" ;
        $headers .= "X-Priority: 3\r\n" ;
        $headers .= "X-Mailer: PHP mailer\r\n" ;

        print_r(mailutil::sendEmail($name, $toemail, $telephone, $subject, $message, $headers));

    }


}


?>